<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use View;
use DB;
use Auth;
use Cart;
class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //视图共享
       
        view::composer(['admin.admin_show'],function($view){
        //查数据总数
        $auserCount = DB::table('admin')->count();
        $userCount = DB::table('users')->count();
        $shopCount = DB::table('shop')->count();
        $goodsCount = DB::table('goods')->count();
        $orderCount = DB::table('order')->count();
            $view->with([
                'auserCount'=>$auserCount,
                'userCount'=>$userCount,
                'shopCount'=>$shopCount,
                'goodsCount'=>$goodsCount,
                'orderCount'=>$orderCount,
                ]);

        });

        view::composer(['layouts.home'],function($view){
        //查购物车数量
        if(empty(Auth::user()->id)){
            $count = 0;
            $view->with([
                'count'=>$count,
                ]);
        }else{
            $uid = Auth::user()->id;
            $count = Cart::instance($uid)->count();
            $view->with([
                'count'=>$count,
                ]);
        }

        });

    

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
